const mongoose = require('mongoose');
const info = require('../config/info.js');
mongoose.connect(info.url + info.dataBase);

const { Schema } = mongoose;

//user表
const users = new Schema({
    userId: {
        type: String,
        required: true
    },
    name: {
        type: String,
        required: true
    },
    password: {
        type: String,
        required: true
    },
    phoneNumber: {
        type: String,
        required: true
    },
    avatarImg: {
        type: String
    },
    exp: Number,
    grade: String,
    coin: Number,
    favourite: [{
        videoId: {
            type: String
        }
    }],
    publish: [{
        videoId: {
            type: String,
            required: true
        }
    }],
    fans: [{
        userId: {
            type: String,
            required: true
        }
    }],
    subscribe: [{
        userId: {
            type: String,
            required: true
        }
    }]
});

//video表
const video = new Schema({
    videoId: {
        type: String,
        required: true
    },
    videoUrl: String,
    coverUrl: String,
    views: Number,
    title: String,
    info: String,
    time: Number,
    pubTime: String,
    pubUserId: String,
    comments: [{
        userId: {
            type: String,
            required: true
        },
        content: {
            type: String
        },
        date: {
            type: String
        }
    }]

})
const db = {
    users: mongoose.model('users', users),
    video: mongoose.model('videos', video)

    //.model('collectionName','schema');
}
module.exports = db;